package com.example.myapplication;

import java.util.ArrayList;
import java.util.List;

public class Utils {
    public static boolean isValidUsername(String user){
        //return user != null && user.matches("[a-zA-Z0-9]{10,20}");
        return true;
    }
    public static boolean isValidPassword(String password){
        //return password != null && !password.isEmpty();
        return true;
    }
    public static boolean isEqualPassword(String password,String repassword){
        return password.equals(repassword);
    }

    public static List<Integer> getWeekList(String weeksString){
        List<Integer> weekList=new ArrayList<>();
        if(weeksString==null||weeksString.length()==0) return weekList;

        weeksString=weeksString.replaceAll("[^\\d\\-,]", "");
        if(weeksString.contains(",")){
            String[] arr=weeksString.split(",");
            for (String s : arr) {
                weekList.addAll(getWeekList2(s));
            }
        }else{
            weekList.addAll(getWeekList2(weeksString));
        }
        return weekList;
    }

    public static List<Integer> getWeekList2(String weeksString){
        List<Integer> weekList=new ArrayList<>();
        int first=-1,end=-1,index=-1;
        if((index=weeksString.indexOf("-"))!=-1){
            first=Integer.parseInt(weeksString.substring(0,index));
            end=Integer.parseInt(weeksString.substring(index+1));
        }else{
            first=Integer.parseInt(weeksString);
            end=first;
        }
        for(int i=first;i<=end;i++)
            weekList.add(i);
        return weekList;
    }

    public static int changeDayofWeek(String dayofWeek){
        int number = 0 ;
        switch (dayofWeek){
            case "周一":
                number=1;
                break;
            case "周二":
                number=2;
                break;
            case "周三":
                number=3;
                break;

            case "周四":
                number=4;
                break;
            case "周五":
                number=5;
                break;
            case "周六":
                number=6;
                break;
            case "周日":
                number=7;
                break;
            default:
                break;

        }
        return number;
    }
}
